// audiosettingdlg.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"

#include "audiosettingdlg.h"
#include "../RMSLib/AudioOut/AudioFactory.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAudioSettingDlg dialog


CAudioSettingDlg::CAudioSettingDlg(ClientInterface* pClient, CWnd* pParent /*=NULL*/)
	: CDialog(CAudioSettingDlg::IDD, pParent)
{
	setClient(pClient);
	//{{AFX_DATA_INIT(CAudioSettingDlg)
	//}}AFX_DATA_INIT
}

void CAudioSettingDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAudioSettingDlg)
	DDX_Control(pDX, IDC_COMBO1, m_Combo);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAudioSettingDlg, CDialog)
	//{{AFX_MSG_MAP(CAudioSettingDlg)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAudioSettingDlg message handlers

BOOL CAudioSettingDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	AudioDriverList drl;
	AudioFactory::Instance()->GetAudioDriversList( drl );

	AudioDriverList::iterator it = drl.begin();
	while(it != drl.end())
	{
		m_Combo.AddString ( (*it).c_str() );
		++it;
	}

	m_nPrevInd = 0;
	m_bFirst = true;

	m_Combo.SelectString(0, getAudioDriverName());
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CAudioSettingDlg::OnSelchangeCombo1() 
{

	int ind = m_Combo.GetCurSel();
	if(ind == CB_ERR)
	{
		AfxMessageBox("Error!");
		return;
	}

	if((ind != m_nPrevInd) || m_bFirst)
	{
		m_bFirst = false;
		m_nPrevInd = ind;
		if(!ReloadDriver(ind))
		{
			MessageBox("Cannot change stylizer!");
		}
	}
	
}

bool CAudioSettingDlg::ReloadDriver(int ind)
{
	CString driver_name;

	m_Combo.GetLBText(ind, driver_name);
	if(driver_name.IsEmpty())
	{
		return false;
	}

	String name = (LPCSTR)driver_name;

	m_strSelectedAudio = name;



	return true;

}
